package com.haojiang.mh.remote.base

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast


/**
 * 所有activity的基类
 */
abstract class BaseActivity : AppCompatActivity(), AnkoLogger {

    protected var isInterruptProcess = false
    protected lateinit var context: BaseActivity

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        context = this
        //设置statusbar的图标颜色高亮反转
//        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        //设置statusbar的颜色
//        getWindow().setStatusBarColor(Color.parseColor("#000000"));
        setContentView(getLayoutId())
        initListener()
        initData()
        if (isInterruptProcess) finish()
    }

    /**
     * 获取布局id
     */
    abstract fun getLayoutId(): Int

    /**
     * adapter和 listener
     */
    open protected fun initListener() {}

    /**
     * 初始化数据
     */
    open protected fun initData() {}

    fun showToast(msg: String) {
        runOnUiThread { Toast.makeText(context, msg, Toast.LENGTH_SHORT).show() }
    }

    override fun onDestroy() {
        initDestroy()
        super.onDestroy()
    }

    open protected fun initDestroy() {

    }

    /**
     * 开启一个activity关闭当前的activity
     */
    inline fun <reified T : BaseActivity> startActivityAndFinish() {
        startActivity<T>()
        finish()
    }

}